﻿using System;
using System.IO;
using AlertSystem;

namespace AlertClient
{
    internal class AlertInfo
    {
        private static readonly string TmpPath;
        static AlertInfo()
        {
            var basePath = Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]);

            basePath = Path.Combine(basePath, "temp\\Data");
            if (!Directory.Exists(basePath))
                Directory.CreateDirectory(basePath);

            TmpPath = basePath;
        }

        public static void ShowDialog(IAlertItem itm)
        {
            if (itm.Data == null)
                return;

            var file = Path.Combine(TmpPath, "data.xml");

            try
            {
                File.WriteAllText(file, itm.Data.ToString());

                AlertInfoWnd.ShowDialogInfo(file);
            }
            finally
            {
                
                if (File.Exists(file))
                    File.Delete(file);
            }
        }
    }
}